package com.syni.mdd.yhd.common.all.service;

import com.syni.mdd.yhd.common.all.constants.Constants;
import com.syni.mdd.yhd.common.all.dao.jpa.BmsUserLoginLogDao;
import com.syni.mdd.yhd.common.all.dao.jpa.BmsbusinessDao;
import com.syni.mdd.yhd.common.all.entity.BmsBusiness;
import com.syni.mdd.yhd.common.all.entity.BmsUserLoginLog;
import com.syni.mdd.yhd.common.all.entity.BmsVideo;
import com.syni.mdd.yhd.common.all.service.impl.BaseService;
import com.syni.mdd.sjb.common.component.utils.common.utils.RequestHeaderData;
import com.syni.mdd.yhd.common.all.utils.RequestParamUtils;
import com.syni.mdd.sjb.common.component.utils.common.utils.ResultMapHelper;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.domain.Sort;
import org.springframework.stereotype.Service;

import java.util.*;

/**
 * @className BmsUserOperationLogService
 * @description TOO
 * @Author cfx
 * @DATE 2019/4/9 12:04
 * @VERSION 1.0
 **/
@Service
public class BmsUserLoginLogService extends BaseService<BmsUserLoginLog, Integer> {

    @Autowired
    BmsUserLoginLogDao bmsUserLoginLogDao;

    @Override
    public BmsUserLoginLogDao getBaseDao() {
        return bmsUserLoginLogDao;
    }

    public Map<String, Object> recordUserLoginOp(Integer userId, String loginDistrict, Integer loginEntryType) {
        RequestHeaderData requestHeaderData = new RequestHeaderData();
        BmsUserLoginLog bmsUserLoginLog = new BmsUserLoginLog();
        bmsUserLoginLog.setBmsUserId(userId);
        bmsUserLoginLog.setLoginDistrict(loginDistrict);
        bmsUserLoginLog.setLoginEntry(loginEntryType);
        bmsUserLoginLog.setLoginTime(new Date());
        bmsUserLoginLog.setFromOrigin(Constants.USER_CLIENT);
        bmsUserLoginLog.setLoginIp(requestHeaderData.getString("x-forwarded-for"));
        bmsUserLoginLog.setPhoneModel(requestHeaderData.getString("models"));
        bmsUserLoginLogDao.save(bmsUserLoginLog);
        return ResultMapHelper.success(bmsUserLoginLog,"记录成功");
    }
}
